package top.houry.im.client.handler.impl;

import io.netty.channel.ChannelHandlerContext;
import javafx.application.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.houry.im.client.controller.ImClientMainUiController;
import top.houry.im.client.event.ImClientUiLoginEvent;
import top.houry.im.client.handler.ImClientMsgTypeHandler;
import top.houry.im.client.proto.ImMessage;
import top.houry.im.ui.controller.ImUiMainController;

import java.util.Date;
import java.util.List;

public class ImClientFriendsRecvServiceImpl implements ImClientMsgTypeHandler {
    private static final Logger log = LoggerFactory.getLogger(ImClientFriendsRecvServiceImpl.class);
    @Override
    public void processImMsg(ImMessage.Client client, ChannelHandlerContext ctx) {
        try {
            ImUiMainController mainController = ImClientMainUiController.getInstance();
            ImMessage.UserFriendsResp friends = ImMessage.UserFriendsResp.parseFrom(client.getBytesData());
            List<ImMessage.FriendInfo> friendsList = friends.getFriendsList();
            Platform.runLater(() -> friendsList.forEach(friend -> {
                String friendNickName = friend.getFriendNickName();
                String friendId = friend.getFriendId();
                mainController.addFriendUser(false, friendId, friendNickName, "");
            }));
        } catch (Exception e) {

        }

    }
}
